package com.lry.jvm.classfile.constantpool;

import com.lry.jvm.classfile.ClassReader;

public class ConstantInvokeDynamicInfo implements ConstantInfo {

    private ConstantPool cp;
    private int bootstrapMethodAttrIndex;
    private int nameAndTypeIndex;

    public ConstantInvokeDynamicInfo(ConstantPool cp, ClassReader reader){
        this.cp = cp;
        this.bootstrapMethodAttrIndex = reader.nextU2ToInt();
        this.nameAndTypeIndex = reader.nextU2ToInt();
    }

    public String getValue()  {
        return  cp.getUTF8(nameAndTypeIndex);
    }

    @Override
    public String toString() {
        ConstantInfo[] constantInfos = cp.getConstantInfos();
        ConstantNameAndTypeInfo nameAndTypeInfo = (ConstantNameAndTypeInfo) constantInfos[nameAndTypeIndex];
        return nameAndTypeInfo.toString();
    }
}
